A set of classes for using WASTE with the Think Class Libraries
by Dan Crevier <mailto:dan@rhino.harvard.edu>
Signficant contributions by Mark Alldritt
version 1.8
November 4, 1995
Introduction
This is a set of classes I've written to use Marco Piovanelli's text edit replacement WASTE with the Think Class Libraries. It only works with versions 2.0.3 or later of TCL. It should work with every version of WASTE, but it is hard to test everything. It has been tested with versions up to 1.2a3. It has been tested with Symantec C++ 8.0, Think C 7.0 and CodeWarrior 7.
For more information on WASTE, see <http://cirrus.sprl.umich.edu>.
I wanted to use WASTE in one of my applications mainly for the ability to use more than 32K of text, and to use inline input for Japanese. I am releasing these classes as public domain, so you are free to use them as you see fit. Remember to give Marco Piovanelli credit if you use WASTE, and you can give me some credit if you feel like it. If you use these classes, I'd be very interested in any bug reports (especially if they include fixes) and any improvements anyone makes. I'd like to thank Marco Piovanelli both for making WASTE available and for his help in figuring out how to get it to work with the class libraries.
If you have used a previous version of the classes, see the what's new section.
There are 6 classes included. They are:
CWASTEText - a subclass of CAbstractText which is much like CStyleText
CWASTEDlgText - a subclass of CWASTEText which is a bit like
CDialogText, but without all of the validation features. It
has a border, broadcasts changes when the text changes,
and passes return, enter and escape to the supervisor.
CTSMSwitchboard - a subclass of CSwitchboard which deals
with Text Service Manager events.
CWASTEEditTask - a class for handling undo with CWASTEText with WASTE 1.0
CWASTEStyleTask - a class for handling undo'ing style changes with CWASTEText
with WASTE 1.0
CWASTETask - a class for handling undo with WASTE 1.1.
I've also included a slightly modified version of TinyEdit, called WASTEEdit, which uses WASTE as a simple example program.
You are free to use these classes in any of your products (freeware, shareware, or commercial).
Adding WASTE Support
If you wish to use these classes in your application, you need to add the following to your application class:
See WASTEEdit for an example. Most of this stuff is to provide inline input. Even if you don't use Japanese on your system, I recommend leaving the support there for those that do have inline input.
CWASTEText
CWASTEText is a subclass of CAbstractText, and is very similar to CStyleText. In addition, I have added the following functions:
StopInlineSession() - Stops the current inline input session
and validates the text.
InsertWithStyle() - Lets you insert some text and it's
corresponding StScrpHandle information all in one step.
InsertWithStyleSoup() - Lets you insert some text and it's
corresponding StScrpHandle information and soup all in one step.
(WASTE 1.1 only)
Clear() - clears the text in the class without any excess
highlighting.
CopyRangeWithStyle() - gets the text and styles for a range
of text all in one step.
CopyRangeWithStyleSoup() - gets the text, styles, and soup for a range
of text all in one step. (WASTE 1.1 only)
SetOutlineHighlighting() - turns outline highlighting on or off. Returns old
setting.
SetFontNumberAll() - sets the font of all of the text.
SetFontNameAll() - sets the font of all of the text.
SetFontSizeAll() - sets the size of all of the text.
SetFontStyleAll() - applies a style to all of the text
TempSelectAll() - temporarily selects all of the text while deactivating the text
and turning off outline hilighting so that the selection won't show up. It can
be restored by Restore selection. This is useful when you want to apply
something to all of the text without seeing all of the text flash. It is a
protected routine used by Clear() and the Set*All() functions.
SetFontColor() - sets the color of the selection
SetFontColorAll() -sets the color of all of the text
InsertPicture() - inserts a picture at the current insertion point (WASTE 1.1 only)
InsertSound() - inserts a sound at the current insertion point (WASTE 1.1 only)
InstallDragHandlers() - installs the necessary handlers to receive drags (see
Drag and Drop section below)
RemoveDragHandlers() - removes drag handlers
CopyWithStyleSoup() - copies text with style and soup information (WASTE 1.1 only)
InstallTabHandlers() - installs hooks for using tab code (with CWASTE 1.1 or later only)
GetRunInfo() - gets the information about the style run at the given offset
GetChar() - gets the character at an offset
SetLineWidth() - changes the line width (where lines wrap). -1 wraps to the pane width.
TCL isn't good at supporting text without fixed height lines. SetWholeLines(true) doesn't work well. I set the scrolling steps to 12 vertically and 4 horizontally when it's in a scroll pane. Something more intelligent could probably be done.
CWASTEDlgText
CWASTEDlgText was made to provide some of the funcitonality of CDialogText. A dialogTextChanged message is broadcast when the text is changed. This wasn't easy for text being entered with inline input, but I think I have it working with a WEPostUpdate routine. It may be broadcasting the message more often than it needs to, but that's ok with me.
It also has a border, just like CDialogText, and passes tab, return, enter, and escape to the supervisor instead of typing them.
I added the GetTextString() method to get the text into a Str255.
CTSMSwitchboard
This is a subclass of CSwitchboard which handles Text Service Manager events.
CTSMDesktop
This is a subclass of CDesktop that lets the Text Service Manager set the cursor.
Undo Support
With WASTE 1.0, the two classes CWASTEEditTask and CWASTEStyleTask are used for undo support. With WASTE 1.1, the class CWASTETask is used to provide undo support using WASTE 1.1's built in undo support. You need to add the appropriate classes to your project. When using CWASTETask, you must add the string "Drag" to STR# resource 130 so you get the "Undo Drag" message in the edit window.
Drag and Drop support
WASTE 1.1 supports dragging and dropping of text. You don't have to do any work to make it so that users can drag text out of CWASTEText panes. If you want to let the user drag text into a CWASTEText pane, you should call CWASTEText::InstallDragHandlers() for that pane. Note: you cannot call InstallDragHandlers() for more than one CWASTEText pane per window. I hope to be able to remove this restriction soon, but it will require some minor modifications to WASTE itself, or more support for Drag and Drop in TCL. Before you can call InstallDrag Handlers, you must add the following to your application class:
if (Gestalt(gestaltDragMgrAttr, &response) != noErr) return false;
if ((response & (1 << gestaltDragMgrPresent)) == 0) return false;
if ((Ptr)InstallTrackingHandler == kUnresolvedSymbolAddress) return false;
return true;
}
Using with TCL 1.1.3
Romain Vignes modified the classes to work with TCL 1.1.3. I haven't tested it out myself. You need to add the following to your prefix:
#define __LONGCOORDINATES__ 1 // Long coordinates services are
// handled by the TCL.
#define TCL_VERSION 0x01010300 // Your version of TCL
WASTE Object Handler Archive
If WASTE_OBJECT_ARCHIVE is defined, CWASTEText will use Michael Kamprath's WASTE Object Handler Archive for the object handlers. In this case, you don't need to add the WASTE TCL sound icon resource (but you must include the Object Archive one). It also adds the function InsertFSSpec().
The object archive included with WASTE 1.2a3 doesn't include the HFS stuff, so InsertFSSpec() won't work with that version. It also uses other filenames. I haven't put in explicit support for this version, I'm going to wait to see how it evolves.
WASTEEdit
WASTEEdit is a slightly modified version of TinyEdit to get it to work with WASTE. I tried to do the minimum modifications necessary to get it to work, so I haven't added any functionality. With a little work, I think a nice application could be made out of it. Right now, it's almost 10 times as big as WASTE Demo, and doesn't do quite as much. It would be really great if someone wanted to add all the scripting support to it, so we would have a nice replacement for the Scriptable Text Editor.
I compiled this version with the WASTE Object Handler Archive, CWASTE 1.2a3 with Internet Config support (so cmd-clicking URL's should work), and the tab support code. You may need to change the #defines in the prefix options and change the files that are included in the project.
Using with Visual Architect
Michael Grinner got me started on using WASTE-TCL with VA. Basically, if VA_COMPATIBLE_IO is defined to 1, CWASTEText has the same PutTo and GetFrom routines as CEditText and CWASTEDlgText has the same PutTo and GetFrom routines as CDialogText. Therefore, you can define new classes in VA with names like CVAWASTEText and CVAWASTEDlgText that are based on CEditText and CDialogText, with library classes CWASTEText and CWASTEDlgText. Then, you can make objects of type CVAWASTEText and CVAWASTEDlgText in your VA views. I've included a simple demo. Note that CWASTEDlgText doesn't handle all of the validation stuff that CDialogText does...
What's new
• Version 1.1
Unfortunately I haven't kept track of the changes made in the classes very well. There were many changes, most of them for improved error checking. Marco Piovanelli and Mark Alldritt made many contributions, and I made some changes myself. Also, I have used the classes with my port of WASTE to C. In the file CWASTEText.cpp, you need to define/undefine CWASTE depending on whether or not you are using the C version of WASTE.
• Version 1.2
The most significant change for this version is support for WASTE 1.1. It includes drag and drop support as well as support for inserting pictures. Also, I have incorporated some bug fixes by Martin Fricke and some of my own.
• Version 1.3
Added functions InsertWithStyleSoup and CopyWithStyleSoup which insert/copy the text, styles, and soup.
As of WASTE 1.1a5 and CWASTE1.1r7 and later, the way tab code is handled is different. In CWASTEText.h, #define WASTE_TABS if you are using one of these new versions, and WASTE_AUTO_TABS if you want the tab handlers to be automatically installed. Otherwise, you have to install InstallTabHandlers for each CWASTEText that you want to use tabs in.
• Version 1.4
Added sound handlers as donated by Leonard Rosenthal. Added InsertSound() to add sounds. You must add the resource file "Sound Icon.rsrc" to your project.
Modified CEditDoc to save/load style and soup information.
Stopped including WASTEEdit 1.0 (WASTE 1.1 is very stable)
If you make Brian L. Matthews <blm@halcyon.com>'s modifications to TCL, click-through will be supported (you can drag something out of a window even if it isn't in front). Note: The demo isn't compiled with this support.
• Version 1.5
Changed to work with WASTE 1.1a7 (CWASTE 1.1r12) or later. Will not work with earlier version of WASTE 1.1.
Note: IViewTemp won't work for specifying non-editable text because macWE isn't set up before specify is called, so it can't set the readonly flag for the WASTE instance. It shouldn't be hard to fix this, or work around it.
Added post update proc to make it keep up with typing that goes outside of the visible area during inline input, as suggested by Martin Sladok.
There are probably other changes I forgot to document.
• Version 1.6
Modified UpdateMenu() to check the correct color item in the menu.
Added WASTETask class to provide undo support using WASTE 1.1 built in support (thanks to help from Jud Spencer). It may not allow styling of pane's with styleable==false.
Pre and post update routines moved to static functions.
• Version 1.7 7/2/95
Added a bunch of improvements by Martin Sladok for dealing with multiple CWASTEText's in one window for printing and undo'ing.
Got rid of curWASTEText static variable, and instead store the CWASTEText * as the refcon for the WASTE instance, and use that in the various callback routines.
Added some PutTo() and GetSome() routines suggested by Martin Sladok. I have not tested them.
Changed the constructor and I() function to optionally let you turn on/off objects, undo support, drag and drop, outline highlighting, and offscreen drawing.
Changed the way CTSMSwitchboard works -- now there is also a CTSMDesktop.
If already typing, WEKey() doesn't make a new CWASTETask.
Fixes in CalcWERects() from Martin Sladok.
Now tested with SC++ 8.0, and WASTEEdit includes a SC++ 8.0 project
• Version 1.8 11/4/95
ResizeFrame only calls WECalText() if width changes.
Added GetRunInfo() to get the WASTE information about style runs.
Aded GetChar() to get the character at an offset, taking two-byte scripts into account.
Added SetLineWidth() from Jan Petersen.
Simplications of CTSM* by Steve Gilardi.
Fixed object I/O stuff (thanks everyone)
Updated to latest TCL style of prefixing TCL routines with "TCL", like TCLForgetObject().
When using WASTE 1.2a3 or later, takes advantage of the new redraw flag, so redrawing will be correctly enabled/disabled in the routines that take a redraw flag. This gets rid of the flickering effects that took place with older versions of WASTE.
The #defines are now done more intelligently. See CWASTEText.h for details on what each one does. If you want to change a #define, I suggest you put the #define in a prefix file, and that will override the default in CWASTEText.h.
Patches to work with TCL 1.1.3 by Romain Vignes. See comments in section above.
Removed Notify(NULL)'s. At least in some cases they aren't the appropriate thing to do. You may need to call it on your own if you do something to a CWASTEText that you don't want the user to undo.
CEditText and CDialogText compatible I/O routines for use with VA, as suggested by Michael Grinner when VA_COMPATIBLE_IO is defined. This makes it easy to use WASTE-TCL in VA. A demo is included.
Printing seems to sometimes break lines across pages. I haven't figured out why yet, any help would be appreciated.